package com.youtills.core.config;

import com.youtills.core.lang.CollectionUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: ravi
 * Date: 9/5/12
 * Time: 7:11 PM
 * To change this template use File | Settings | File Templates.
 */
class ConfigMulti implements IConfigMulti {

    private final String prefix;
    private final String suffix;
    private final String defaultValue;
    private final List<IConfig> configs = new ArrayList<IConfig>();

    ConfigMulti(String prefix, String suffix, String defaultValue) {
        this.prefix = prefix;
        this.suffix = suffix;
        this.defaultValue = defaultValue;

        Set<String> keys = ConfigurationLoader.getPropertyNames();
        if(!CollectionUtil.isEmpty(keys)){
            for(String key : keys){
                if(key != null){
                    if((prefix == null || key.startsWith(prefix)) && (suffix == null || key.endsWith(suffix)) ){
                        configs.add(new Config(key, defaultValue));
                    }
                }
            }
        }

    }

    public List<IConfig> getConfigs() {
        return Collections.unmodifiableList(configs);
    }

    public String getPrefix() {
        return prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public String getDefaultValue() {
        return defaultValue;
    }
}
